package study.repository.user;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import study.domain.user.User;
import study.domain.user.User_;

/**
 * 사용자 관련 조건
 *
 * @author Barney Kim
 */
public class UserSpecifications {

	/**
	 * 사용자명과 일치하는 조건
	 *
	 * @param username
	 *            사용자 명
	 */
	public static Specification<User> findByUsername(final String username) {
		return new Specification<User>() {
			@Override
			public Predicate toPredicate(Root<User> root,
					CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.equal(root.get(User_.username), username);
			}
		};
	}
}
